SimpleDynamicModels

Return to big picture - model types

Dynamic Models

Spatial models that interact - similar to dynamic

Dynamic modeling

Why you should care

Vocab

Examples - note the feedback loops (time dependency)

Feekback is a key feature of dynamic models

Stability

Simple Example

Implementing Dynamic Models in R

Dynamic models always involves derivatives (equations that express how things change from time step to time step or place to place )

Implement population growth as a derivative - a model of population change

# note that we include time here but we don't use it; we will need this later
source("../R/dexppop.R")

dexppop
## function (time, P, r) 
## {
##     dexpop = r * P
##     return(list(dexpop))
## }
# see how it works
dexppop(P=20, r=0.01)
## [[1]]
## [1] 0.2
#what is this?

# notices this is the same as
dexppop(t=100,P=20, r=0.01)
## [[1]]
## [1] 0.2
# lets look at this for a range of initial populations
pops = seq(from=1, to=100)
tmp = pops %>% map(~dexppop( time=0,r=0.01, P=.x))
pchange = unlist(tmp)


pdyn = data.frame(pops, pchange)
ggplot(pdyn, aes(pops, pchange))+geom_point(col="green", size=1.5)

# why is this a straight line?
# how many new individuals are born at each population level

# try this - add a carrying capacity (dP/dt = 0 if P > carryingcapacity)

Integration

What if we wanted to look at population in 20 years given an initial condition

Two options

Explicit Solution is available

source("../R/exppop.R")

exppop
## function (T, P0, r, K) 
## {
##     P = P0 * exp(r * T)
##     if (P > K) {
##         P = K
##     }
##     return(P)
## }
# gives population after any time given an initial population

# 20 rabbits, growth rate of 0.01 how many in 30 years
exppop(T=30, P0=20, r=0.01, K=1000)
## [1] 26.99718
# if we want to see how population evolves over time - generate a time series by running our model for each point in time

initialrabbits = 20
years = seq(from=1, to=100, by=2)
Ptime = years %>% map_dbl(~exppop( P0=initialrabbits, r=0.01, K=1000, T=.x))

# keep track of what times we ran
Ptime = data.frame(P=Ptime, years=years)

ggplot(Ptime, aes(years,P))+geom_point()+labs(x="years",y="Rabbit Population")

# try generating results for maximum and minimum possible r values to compare (guess at what you think)


max_r = 0.1
min_r = 0.01
K = 1000

tmp = years  %>% map_dbl(~exppop(r=max_r, P0=initialrabbits, K=K, T=.x))
Ptime$Pmaxr = tmp
tmp = years %>% map_dbl(~exppop(r=min_r, P0=initialrabbits, K=K, T=.x))
Ptime$Pminr = tmp

head(Ptime)
##          P years    Pmaxr    Pminr
## 1 20.20100     1 22.10342 20.20100
## 2 20.60909     3 26.99718 20.60909
## 3 21.02542     5 32.97443 21.02542
## 4 21.45016     7 40.27505 21.45016
## 5 21.88349     9 49.19206 21.88349
## 6 22.32556    11 60.08332 22.32556
Ptimep = Ptime %>% gather(key="r",value="P",-years)
ggplot(Ptimep, aes(years,P, col=r))+geom_point()+labs(x="years",y="Rabbit Population")

# notice how population becomes unstable for high growth rates!